package org.zn.mvcbase.exception;

import java.io.IOException;
import java.util.Map;

import org.springframework.http.MediaType;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.HttpMessageNotWritableException;
import org.springframework.web.servlet.ModelAndView;

/**
 * ajax 模式相应
 * 
 * @ProjectName:zqdk-mvcbase
 * @Description:
 * @author: 周楠
 * @date 2017年3月6日 上午10:26:37
 */

public class AjaxExceptionResponseState extends AbstractResponseHandlerState {

	@SuppressWarnings("unchecked")
	@Override
	public ModelAndView exceptionResponse(Map<String, Object> exMessage) {

		exMessage.remove(ExceptionResponseMessage.ERRORPAGE_KEY);
		
		try {
			HttpMessageConverter<Map<String, Object>> hmc= (HttpMessageConverter<Map<String, Object>>) converterMap.get("jsonConverter");
			hmc.write(exMessage,MediaType.APPLICATION_JSON, outputMessage);
		} catch (HttpMessageNotWritableException | IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		return null;
	}

}
